package com.imau.controller;

import com.imau.bean.User;
import com.imau.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/user")
public class UserControllerBack {

    @Autowired
    private UserService userService;


    @RequestMapping("/info")
    public String getUser(@RequestParam("id") Integer id, @RequestParam("userName") String userName) {


        System.out.println("id=" + id);
        System.out.println("userName=" + userName);
        return "userInfo";
    }

    @RequestMapping("/testUser")
    public User testUser(@RequestBody User user) {


        System.out.println(user);
        return user;
    }

    @RequestMapping("/arrayParam")

    public String testArrayParam(String likes[]) {


        System.out.println(Arrays.asList(likes));
        return "arrayParam";
    }

    @RequestMapping("/testCollectionParam")

    public String testCollectionParam(@RequestParam List<String> likes) {


        System.out.println(likes);
        return "testCollectionParam";
    }

    @RequestMapping("/testDate")
    public  String testDate(@DateTimeFormat(pattern = "yyyy-MM-dd") Date date)
    {
        SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(new Date());
        System.out.println(date);
        return "{\"info\":\"日期\"}";
    }

    @RequestMapping("/testResponse")
    public ModelAndView testResponse(@DateTimeFormat(pattern = "yyyy-MM-dd") Date date)
    {
        System.out.println("响应...");
        //数据模型信息存储
        ModelAndView modelAndView = new ModelAndView("index.jsp");
        return modelAndView;
    }
    /**
     * springMVC 响应：返回值字符串 ，代表视图名称
     */
}
